const MagicString = require('magic-string')

function compareIsTarget (query) {
  return query.has('setup') && query.has('name')
}

function padEndString (query) {
  return `__name: 'index', name: '${query.get('name')}',`
}

module.exports = function (source) {
  const query = new URLSearchParams(this.resourceQuery)
  if (compareIsTarget(query)) {
    const modifyStr = new MagicString(source)
    modifyStr.replace("__name: 'index',", padEndString(query))

    console.log('\r\n', this.query)
    console.log(this.resourcePath)

    return modifyStr.toString()
  }

  return source
}
